package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.ProductSerialFlowEntity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface ProductSerialFlowModel extends IModel<ProductSerialFlowEntity> {

    /**
     * 获取符合查询条件的记录
     *
     * @param param 查询条件
     * @return Integer
     * @author JianTao.Xiong
     * @date 2020/5/19
     * @since V1.0
     */
    @Override
    List<ProductSerialFlowEntity> findEntitys(Map<String, Object> param);

    /**
     * 获取符合查询条件的记录总数
     *
     * @param param 查询条件
     * @return 符合查询条件的记录总数
     */
    @Override
    Integer getEntitysCount(Map<String, Object> param);

    /**
     * 批量插入序列号流水
     * @param productSerialFlowEntitys 流水
     */
    void insertBatch(List<ProductSerialFlowEntity> productSerialFlowEntitys);

    /**
     * 批量删除
     * @param refIdIn 关联单据id
     * @param corpid 公司id
     * @param businessType
     * @param enableSerialProductIds
     * @return 删除记录数
     */
    Integer deleteBatch(List<Long> refIdIn, String corpid, Integer businessType, List<Long> enableSerialProductIds);

    /**
     * 批量删除
     * @param idIn id
     * @param corpid 公司id
     * @return 删除记录数
     */
    Integer deleteBatchById(List<Long> idIn, String corpid);

    /**
     * 获取序列号最近时间的一条流水记录
     * @param corpid 公司id
     * @param seqKey 序列号
     * @param refId
     * @return ProductSerialBalanceEntity
     * @throws XbbException 异常
     */
    ProductSerialFlowEntity getLastSerialFlow(String corpid, String seqKey, Long refId) throws XbbException;

    void delByRefProductAndBusinessType(String corpid, Long refProductId, int businessType);

    List<ProductSerialFlowEntity> getBySeqKey(String seqKey, String corpid);

    List<ProductSerialFlowEntity> getFlowByRefIdAndBusiness(List<Long> refIdIn, Integer businessType, String corpid);

    /**
     * 批量更新
     * @param updateSerialFlowList
     * @param corpid
     * @return java.lang.Integer
     * @author 吴峰
     * @date 2022/2/28 11:08
     * @throws XbbException
     */
    Integer updateBatch(List<ProductSerialFlowEntity> updateSerialFlowList, String corpid);

    /**
     *
     * @param corpid
     * @param refId
     * @param refProductIdIn
     * @param businessType
     */
    Integer deleteByRefProductId(String corpid, Long refId, Collection<Long> refProductIdIn, Integer businessType);

    /**
     * 根据产品获取最后一条流水记录
     * @param corpid
     * @author 阮思程
     * @date 2022/9/15 11:08
     * @throws XbbException
     */
    List<ProductSerialFlowEntity> getLastSerialFlowByProductId(Map<String, Object> param) throws XbbException;
}
